package com.ifnk.portaljava.dapWeb.hlyt.servlet;

/**
 * <p>Title: CallTrace/Query服务类</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2010</p>
 *
 * <p>Company: </p>
 *
 * @author WenSheng.Song.hlyt@gmail.com
 * @version 1.0
 */

import com.ifnk.portaljava.dapWeb.common.MessageBean;
import com.ifnk.portaljava.dapWeb.common.Util;
import com.ifnk.portaljava.dapWeb.dapweb.Command;
import com.ifnk.portaljava.dapWeb.dapweb.SignallingPacket;
import com.ifnk.portaljava.dapWeb.socket.Client;
import com.ifnk.portaljava.dapWeb.socket.CommandHistory;
import com.ifnk.portaljava.dapWeb.socket.CommandsendToProxy;
import com.ifnk.portaljava.dapWeb.socket.FlexUtil;
import com.ifnk.portaljava.hlyt.dao.IDeviceLookupJdbcDao;
import com.ifnk.portaljava.hlyt.test.CdrPktInfo;
import com.ifnk.portaljava.hlyt.test.Tshark;
import com.ifnk.portaljava.hlyt.test.Tshark2;
import com.ifnk.portaljava.hlyt.test.Tshark3;
import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
import flex.messaging.MessageBroker;
import flex.messaging.messages.AsyncMessage;
import flex.messaging.util.UUIDUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.math.BigInteger;
import java.nio.file.ClosedWatchServiceException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@SuppressWarnings({"serial"})
public class CallTraceServlet extends HttpServlet {
    public static final String CDRKEY = "all";
    private static Log loger = LogFactory.getLog(CallTraceServlet.class);
    /*
    public static Map<String, Client> threadMap = Collections
            .synchronizedMap(new HashMap<String, Client>());
            */
    private static Map<String, Client> _threadMap = new ConcurrentHashMap<String, Client>();

    private static Map<String, Tshark3> _tshark3Map = new ConcurrentHashMap<String, Tshark3>();

    private MessageBean bean = new MessageBean();

    public static int XDRLEN = 8;

    public static String SERVLET_TYPE = "normal";

    public static int getXdrLen() {
//        return XDRLEN;
        return 16;
    }

    public static String getServletType() {
        return SERVLET_TYPE;
    }

    static {
        Locale locale = Locale.ENGLISH;
        ResourceBundle localResource = ResourceBundle.getBundle("Socket",
                locale);
        SERVLET_TYPE = localResource.getString("servlet_type");
        if ("new16".equals(SERVLET_TYPE)) {
            XDRLEN = 16;
        } else {
            XDRLEN = 8;
        }
    }

    public static synchronized Client getClient(String clientId) {
        return _threadMap.get(clientId);

    }

    public static synchronized Tshark3 getTshark3(String clientId) {
        return _tshark3Map.get(clientId);
    }

    public static synchronized void putTshark3(String clientId, Tshark3 shark) {
        _tshark3Map.put(clientId, shark);
    }

    public static synchronized void removeStoppedClient() {
        Iterator<Map.Entry<String, Client>> ite = _threadMap.entrySet().iterator();
        while (ite.hasNext()) {
            Map.Entry<String, Client> entry = ite.next();
            Client c = entry.getValue();

            loger.debug("clientmap before remove client: " + c.getClientId() + c.getCp() + c.getSp().flag);

            if (c != null && c.getCp() == null) {
                loger.debug("clientmap remove client: " + c.getClientId());
                ite.remove();
            }
        }

    }

    public void loadDeviceLookupFile() {
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
        IDeviceLookupJdbcDao deviceLookup = (IDeviceLookupJdbcDao) wac.getBean("deviceLookupDaoLocal");
        deviceLookup.init();
    }

    public static synchronized void removeStoppedClient(String clientId) {
        Client c = _threadMap.get(clientId);
        if (c != null && !c.getSp().flag) {
            _threadMap.remove(clientId);
        }
    }

    public static synchronized void putClient(String clientId, Client client) {
        _threadMap.put(clientId, client);
    }

    public static synchronized void removeClient(String clientId) {
        _threadMap.remove(clientId);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }


    private synchronized void doClearClient() {
        Iterator<Map.Entry<String, Client>> entries = _threadMap.entrySet().iterator();

        while (entries.hasNext()) {
        }

    }

    private void doGetStatus(HttpServletRequest request, HttpServletResponse response) {
        ServletOutputStream out = null;
        try {
            response.setContentType("text/html");
            out = response.getOutputStream();

            out.println("<html>");
            out.println("<body>");

            out.println("fixed pcap file delete bug<br/>");
            out.println("add merg tshark properties file<br/>");
            out.println("fix session time out bug<br/>");
            out.println("tshark thread timeout is 10 minute now<br/>");
            out.println("version 0.0.2.0<br/>");
            out.println("2015 06 04<br/>");
            out.println("add soft lte on sdtp feature<br/>");

            out.println("adding 16 long xdr feature<br/>");
            out.println("XDRLEN:" + CallTraceServlet.XDRLEN + "<br/>");

            out.println("2016 08 13<br/>");

            out.println("2016 08 13<br/>");
            out.println("merge chang an version into this<br/>");
            out.println("add servlet kind which can make kind to changan<br/>");
            out.println("and new16 kind for xdr len 16<br/>");
            out.println("2016 08 24<br/>");
            out.println("and load look up device<br/>");
            out.println("2016 10 08<br/>");
            out.println("and load look up device subnet phase<br/>");
            out.println("2016 11 17<br/>");
            out.println("add mtp2 with sctp 64k 2m<br/>");
            out.println("2017 10 20<br/>");
            out.println("fixed the 0x8c subtype bug<br/>");
            out.println("2019 05 29<br/>");
            out.println("add imsi search method<br/>");
            out.println("2019 07 26<br/>");
            out.println("fix none ip bug<br/>");
            out.println("2019 07 31<br/>");
            out.println("fix byte compare bug<br/>");
            out.println("2019 08 01<br/>");

            out.println("fix 2m bug<br/>");
            out.println("2019 11 29<br/>");

            out.println("add 5g soft sdtp if compare<br/>");
            out.println("2020 01 11<br/>");

            HttpSession session = request.getSession(false);
            if (session == null) {
                out.println("this session is null!!!");
            } else {
                out.println("this session id: " + session.getId() + "<br/>");
            }

            int size = _threadMap.size();
            out.println("thread map size: " + size + "<br/>");

            Iterator<Map.Entry<String, Client>> entries = _threadMap.entrySet().iterator();

            while (entries.hasNext()) {
                out.println("-----------------<br/>");

                Map.Entry<String, Client> entry = entries.next();
                String id = entry.getKey();
                Client c = entry.getValue();
                out.println("clientId: " + id + "<br/>");
                if (c.getCp() != null)
                    out.println("proxyid: " + c.getCp().getRequestDateFromProxyId() + "<br/>");
                if (c.getCp() != null && c.getCp().getCh() != null)
                    out.println("command history: " + c.getCp().getCh().getCommandNumber() + "<br/>");
                try {
                    if (c.getSession() != null) {
                        out.println("client http session id: " + c.getSession().getId() + "<br/>");
                        out.println("session create time: " + new Date(c.getSession().getCreationTime()).toString() + "<br/>");
                        out.println("cdrlist: " + c.getSession().getAttribute("cdrlist") + "<br/>");
                    }
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                    out.println("session invalide <br/>");
                }

            }


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e2) {
            e2.printStackTrace();
        } finally {

            try {
                out.println("</body>");
                out.println("</html>");
                out.flush();
                out.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    }

    public void doDownloadPcap(HttpServletRequest request) {
        //Client client = threadMap.get(clientId);
        HttpSession httpSession = request.getSession(false);
        String clientId = "clientId";
        Client client = new Client(clientId, httpSession);
        if (client != null) {
            Locale locale = Locale.ENGLISH;
            ResourceBundle localResource = ResourceBundle.getBundle("Socket",
                    locale);
            String sid = client.getCp().getRequestDateFromProxyId();
            String pcapfilepath = localResource.getString("pacpfilepath");
            String fileSeparator = localResource.getString("separator");
            String pcaprootrooty = pcapfilepath + "summary" + fileSeparator + sid + fileSeparator + "all";
            String pcaprootrooty_file = pcapfilepath + "summary" + fileSeparator + sid + fileSeparator + "all" + fileSeparator + "all-real-" + UUID.randomUUID().toString() + ".pcap";

            CommandHistory ch = client.getCp().getCh();
            SignallingPacket signallingPacket = new SignallingPacket();
            for (int i = 0; i < ch.getCommandNumber(); i++) {

                Command c = ch.getCommandByTimeIndex(i);
                byte[] packet = null;
                if (new File(pcaprootrooty_file).exists()) {
                    packet = signallingPacket.TransformToDataPacket(c.getPkt());
                } else {
                    packet = signallingPacket.convertPacketToPcap(c.getPkt());
                }
                try {
                    savePacketToNativeFile(pcaprootrooty_file, pcaprootrooty, packet, true);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            }
            File f = new File(pcaprootrooty_file);
            //File f = new File("c:/root/d/all.pcap");
//			if(f.exists()) {
//				try {
//
//					OutputStream o = response.getOutputStream();
//					byte b[] = new byte[500];
//					response.reset();
//
//					response.setContentType("application/octet-stream");
//				    response.setHeader("content-disposition", "attachment; filename=all.pcap");
//				    long fileLength = f.length();   //这里的length()返回的是文件的长度,以字节为单位,Long类型
//					String length1 = String.valueOf(fileLength);
//					response.setHeader("Content_Length", length1);  //content-length指的是有效负载的字节(Byte)长度
//					FileInputStream in = new FileInputStream(f);
//					int n;
//					while ((n = in.read(b)) != -1) {
//					    o.write(b, 0, n);
//					}
//					o.flush();
//					o.close();
//					in.close();
//				} catch (FileNotFoundException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				} catch (IOException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//
//			}

        } else {

            Locale locale = Locale.ENGLISH;
            ResourceBundle localResource = ResourceBundle.getBundle("Socket",
                    locale);
            String sid = clientId;
            String pcapfilepath = localResource.getString("pacpfilepath");
            String fileSeparator = localResource.getString("separator");

            //String pcaprootrooty = pcapfilepath + "summary" + fileSeparator + sid + fileSeparator + "all";

            String pcaprootrooty_file = pcapfilepath + "summary" + fileSeparator + sid + fileSeparator + "all.pcap";

            File f = new File(pcaprootrooty_file);
            //File f = new File("c:/root/d/all.pcap");
//			if(f.exists()) {
//				try {
//
//					OutputStream o = response.getOutputStream();
//					byte b[] = new byte[500];
//					response.reset();
//
//					response.setContentType("application/octet-stream");
//				    response.setHeader("content-disposition", "attachment; filename=all.pcap");
//				    long fileLength = f.length();   //这里的length()返回的是文件的长度,以字节为单位,Long类型
//					String length1 = String.valueOf(fileLength);
//					response.setHeader("Content_Length", length1);  //content-length指的是有效负载的字节(Byte)长度
//					FileInputStream in = new FileInputStream(f);
//					int n;
//					while ((n = in.read(b)) != -1) {
//					    o.write(b, 0, n);
//					}
//					o.flush();
//					o.close();
//					in.close();
//				} catch (FileNotFoundException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				} catch (IOException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//
//			}
        }

    }

    private void savePacketToNativeFile(String name, String path,
                                        byte[] pkt, boolean append) throws IOException {
        loger.debug("write byte: " + pkt.length + " to file " + name);
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        DataOutputStream output = new DataOutputStream(new FileOutputStream(
                new File(name), append));
        output.write(pkt);
        output.flush();
        output.close();

    }

    // 开始跟踪
    public void callTraceStart(String clientId, String condition,
                               String protocol, String svrlist, HttpSession session)
            throws IOException {
        session.setAttribute(clientId, System.currentTimeMillis() / 1000);
        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);
        if (client != null) {
            Tshark.clearSessionFile(client);
            client.getSp().setFlag(false);
            client.getCp().getRawDataPackets().clear();
            if (client.getCp().processRawData != null)
                client.getCp().processRawData.interrupt();
            client.interrupt();
            //threadMap.remove(clientId);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        client = new Client(clientId, session);
        session.setAttribute("client", client);
        String tmpUUID = new Util().getUuid();
        client.getCp().setRequestDateFromProxyId(tmpUUID);
        client.setProxySessionId(tmpUUID);  //for delete file from proxy
        client.getCp().setStoped(false);
        if (client.getSp().isNetConnected) {// 只有当能连接上proxy才发送请求
            //threadMap.put(clientId, client);
            putClient(clientId, client);
            client.start();
            CommandsendToProxy commandSend = new CommandsendToProxy();
            commandSend.sendCallTraceStartCommand(client.getSp(), client
                            .getCp().getRequestDateFromProxyId(), condition, protocol,
                    svrlist);
        } else {// client初始化时连接不到proxy向页面发送提示消息
            sendMessage("connectToproxyFailure", false, true, clientId);
            loger
                    .error("WebServer lose proxy connection when sendCallTraceStartCommand");
        }
    }

    // 停止跟踪
    public void StopCommand(String clientId, String opType) throws Exception {
        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);
        if (client != null) {
            CommandsendToProxy commandSend = new CommandsendToProxy();
            commandSend.sendStopCommand(client.getSp(), opType, client.getCp()
                    .getRequestDateFromProxyId());
            client.getCp().setStoped(true);
            client.getCp().packets.clear();
            client.getCp().getData().clear();
        } else {// client初始化时连接不到proxy向页面发送提示消息
            sendMessage("连接已断开", false, false, clientId);
            loger.error("WebServer lose proxy connection when " + opType
                    + " sendStopCommand");
        }
    }

    // 查询cdr的详细信息
    public void RawQuery(String opType, String clientId, String id,
                         byte protocol, int cdr_id, int svr_id, int ts_s, int ts_ns)
            throws Exception {

        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);

        if (client != null && client.getSp().isNetConnected) {
//			client.getCp().getCdrPackets().clear();
//			client.getCp().getRawDataPackets().clear();
            String key = svr_id + "_" + cdr_id + "_" + protocol + "_" + ts_s;
//			client.getCp().setCdrKey(key);


//			tshark.setKey(key);
//			tshark.setClientId(clientId);
//			tshark.setSessionId(client.getCp().getRequestDateFromProxyId());
            CdrPktInfo cdrPktInfo = new CdrPktInfo();
            cdrPktInfo.setCdrKey(key);
            cdrPktInfo.setClientId(client.getClientId());
            cdrPktInfo.setSessionId(client.getCp().getRequestDateFromProxyId());
            Tshark tshark = new Tshark(cdrPktInfo);
            cdrPktInfo.setTshark(tshark);
//			tshark.setCdrPktInfo(cdrPktInfo);
            client.getCp().cdrPktInfoMap.put(key, cdrPktInfo);
//			System.out.println("put key : " + key);
            Tshark.clearCdrPktFile(client, key);
            tshark.start();

            CommandsendToProxy commandSend = new CommandsendToProxy();
            commandSend.sendRawQueryCommand(client.getSp(), opType, client
                            .getCp().getRequestDateFromProxyId(), client.getClientId(),
                    protocol, svr_id, cdr_id, ts_s, ts_ns);
        } else {
            sendMessage("连接已断开请重新点击start开始", false, true, clientId);
            loger.error("WebServer lose proxy connection when " + opType
                    + " sendRawQueryCommand");
        }
    }

    public void clearRawQuery(String clientId) {
        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);
        if (client == null) {
            return;
        }
        client.getCp().getCdrPackets().clear();
        client.getCp().getRawDataPackets().clear();

        Map<String, CdrPktInfo> cdrPktInfoMap = client.getCp().cdrPktInfoMap;
        Iterator<String> iterator = client.getCp().cdrPktInfoMap.keySet().iterator();
        while (iterator.hasNext()) {
            Tshark tshark = cdrPktInfoMap.get(iterator.next()).getTshark();
            if (tshark.isAlive()) {
                tshark.interrupt();
                loger.debug("interrupt : " + tshark.getId() + tshark.getName());
            }
        }
        cdrPktInfoMap.clear();
    }

    public void CDRQueryStart(String opType, String clientId, int starttime,
                              int endtime, String protocol, String svrlist, String condition,
                              HttpSession session, int maxDataNumber) throws Exception {
        session.setAttribute(clientId, System.currentTimeMillis() / 1000);
        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);

        if (client != null) { // 如果client存 在，先清除他的所有现状
            Tshark.clearSessionFile(client);
            client.getSp().setFlag(false);
            client.getCp().getRawDataPackets().clear();
            if (client.getCp().processRawData != null)
                client.getCp().processRawData.interrupt();
            client.interrupt();
            //threadMap.remove(clientId);
            Thread.sleep(2000);
        }
        client = new Client(clientId, session);
        session.setAttribute("client", client);
        String tmpUUID = new Util().getUuid();
        client.getCp().setRequestDateFromProxyId(tmpUUID);
        client.setProxySessionId(tmpUUID);  //for delete file from proxy
        client.getCp().setStoped(false);
        if (client.getSp().isNetConnected) {
            //threadMap.put(clientId, client);
            putClient(clientId, client);
            // 先启动Socket连接，准备接收数据
            client.start();
			/*
			CommandsendToProxy commandSend = new CommandsendToProxy();
			commandSend.sendCDRQueryStartCommand(client.getSp(), tmpUUID,
					starttime, endtime, protocol, svrlist, condition,
					maxDataNumber);
			loger.info("WebServer Send CDRQueryCommand Success " + " protocol:"
					+ protocol + " svrlist: " + svrlist + " condition: "
					+ condition + " starttime: " + starttime + " endtime: "
					+ endtime + " clientId:" + clientId + " UUID:" + tmpUUID
					+ " maxDataNumber:" + maxDataNumber);
					*/
        } else {// client初始化时连接不到proxy向页面发送提示消息
            sendMessage("connectToproxyFailure", false, true, clientId);
            loger
                    .error("WebServer lose proxy connection when sendCDRQueryStartCommand");
        }
    }

    private void closeClient(String clientId) {
        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);
        if (client != null) {
            Tshark.clearSessionFile(client);
            client.getSp().setFlag(false);
            client.getCp().getRawDataPackets().clear();
            if (client.getCp().processRawData != null)
                client.getCp().processRawData.interrupt();
            client.interrupt();
            //threadMap.remove(clientId);
            removeClient(clientId);
        }
        loger.info("WebServer closeClient clientId=" + clientId);
    }

    public void stopPKT(String clientId) {
        //Client client = threadMap.get(clientId);
        Client client = getClient(clientId);
        if (client != null) {
            client.getCp().setPktStoped(true);
            client.getCp().getRawDataPackets().clear();
            if (client.getCp().processRawData != null)
                client.getCp().processRawData.interrupt();
        }
        loger.info("WebServer stopPKT clientId=" + clientId);
    }

    private void sendMessage(String message, boolean stopFlag,
                             boolean errorFlag, String clientId) {
        bean.setMessage(message);
        bean.setStopFlag(stopFlag);
        bean.setErrorFlag(errorFlag);
        MessageBroker messageBroker = MessageBroker.getMessageBroker(null);
        String subTopic = "KeepAlive" + clientId;
        Util.routeMessage(messageBroker, subTopic, clientId, bean);
    }

    private void sendPacketToFlex(String subTopic, String clientId, Object obj) {
        MessageBroker messageBroker = MessageBroker.getMessageBroker(null);
        AsyncMessage msg = new AsyncMessage();
        msg.setDestination("callTraceChannel");
        msg.setHeader("DSSubtopic", subTopic);
        msg.setClientId(clientId);
        loger.debug("subTopic: " + subTopic);
        msg.setMessageId(UUIDUtils.createUUID());
        msg.setTimestamp(System.currentTimeMillis());
        msg.setBody(obj);
        messageBroker.routeMessageToService(msg, null);
    }

    // queryquery init start
    public void queryqueryCallTraceStart(
            String clientId, HttpSession session, String address, int port
    ) {

        Client client = null;
        if (address == null) {
            client = new Client(clientId, session);
        } else {
            client = new Client(clientId, session, address, port);
        }
        String tmpUUID = new Util().getUuid();
        client.getCp().setRequestDateFromProxyId(tmpUUID);
        client.setProxySessionId(tmpUUID);  //for delete file from proxy
        client.getCp().setStoped(false);

        if (client.getSp().isNetConnected) {// 只有当能连接上proxy才发送请求
            session.setAttribute(clientId, System.currentTimeMillis() / 1000);
            session.setAttribute("client", client);
            client.start();
        } else {// client初始化时连接不到proxy向页面发送提示消息
            throw new RuntimeException("client can not connect to proxy 连不上proxy");
        }

        CallTraceServlet.removeStoppedClient();
        Client old_client = getClient(clientId);
        putClient(clientId, client);

        if (old_client != null) {
            old_client.getSp().setFlag(false);
            old_client.getCp().getRawDataPackets().clear();
            if (old_client.getCp().processRawData != null)
                old_client.getCp().processRawData.interrupt();
            old_client.interrupt();
        }
    }

    public String queryQuery(String opType, String clientId, String id,
                             byte protocol, int svr_id, long[] cdrs, long[] times, int startTime)
            throws Exception {

        Client client = getClient(clientId);

        if (client != null && client.getSp().isNetConnected) {

            CdrPktInfo cdrPktInfo = new CdrPktInfo();
            cdrPktInfo.setCdrKey(CDRKEY);

            if ("chanct".equals(CallTraceServlet.SERVLET_TYPE) || protocol == 99) {
                cdrPktInfo.setTsharkChineseArgu("-o mtp3.standard:Chinese+ITU");
            } else {
                cdrPktInfo.setTsharkChineseArgu("-o mtp3.standard:ITU");
            }

            cdrPktInfo.setClientId(client.getClientId());
            cdrPktInfo.setSessionId(client.getCp().getRequestDateFromProxyId());
            Tshark tshark = new Tshark(cdrPktInfo);
            cdrPktInfo.setTshark(tshark);

            client.getCp().cdrPktInfoMap.put(CDRKEY, cdrPktInfo);

            client.getCp().setCh(new CommandHistory());


            Tshark.clearCdrPktFile(client, CDRKEY);
            tshark.start();


            CommandsendToProxy commandSend = new CommandsendToProxy();

            // 这里自己拼 16位 的东西

            int[] zdrs = new int[cdrs.length * 6];
            for (int i = 0; i < cdrs.length; i++) {
                long cdr = cdrs[i];
                String hexString = Long.toHexString(cdr);
                if (hexString.length() != 16) {
                    throw new RuntimeException("cdrid " + cdr + "转16进制有问题，长度不是16位");
                }
                String[] split = hexString.split("(?<=\\G.{8})");// 正则按8位分割

                zdrs[i * 6] = 1650807526; // 随便给的时间戳,后面有空改
                zdrs[i * 6 + 1] = 0;
                zdrs[i * 6 + 2] = 0;
                zdrs[i * 6 + 3] = Integer.parseInt("0e", 16);
                zdrs[i * 6 + 4] = Integer.parseInt(split[0], 16);
                zdrs[i * 6 + 5] = Integer.parseInt(split[1], 16);
            }
            return commandSend.sendQueryQueryCommand(client.getSp(), opType, client
                            .getCp().getRequestDateFromProxyId(), client.getClientId(),
                    protocol, svr_id, zdrs, startTime);


        } else {
            throw new RuntimeException("连接已断开请重新点击start开始");
        }
    }
}
